package com.eastfair.home.service.impl;

import com.eastfair.core.base.R;
import com.eastfair.core.context.StaticContextUtil;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.service.HomeWorkOvertimeService;
import com.eastfair.messagecenter.util.SendMsgUtil;
import com.eastfair.venuebooking.api.WorkOvertimeFeign;
import com.eastfair.venueservice.dto.WorkOvertimeDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 加班申请服务.
 *
 * @author dqq
 * @date 2022 /10/20
 */
@Service
@Slf4j
public class HomeWorkOvertimeServiceImpl implements HomeWorkOvertimeService {

    @Resource
    private WorkOvertimeFeign workOvertimeFeign;

    @Resource
    private SendMsgUtil sendMsgUtil;

    @Override
    public boolean auditWorkOvertime(WorkOvertimeDTO workOvertimeDTO) {
        log.info("auditWorkOvertime - 更新审核结果, workOvertimeDTO={}", workOvertimeDTO);
        R<Boolean> result = workOvertimeFeign.auditWorkOvertime(workOvertimeDTO);
        log.info("auditWorkOvertime - 完成, result={}", result);
        if (!result.getIsSuccess()) {
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        return result.getData();
    }

    @Override
    public boolean sendConfigPayeeInnerMsg(WorkOvertimeDTO workOvertimeDTO) {
        log.info("sendConfigPayeeInnerMsg - 发送配置收款商户的站内信,workOvertimeDTO={}", workOvertimeDTO);
        String content = String.format("主场【%s】，您好，%s已生成，如需收款请到财务系统配置收款账号！", workOvertimeDTO.getHomeId(), "加班订单");
        sendMsgUtil.sendInnerMsgByTeamId(content, workOvertimeDTO.getHomeId(), StaticContextUtil.getProjectSystemScene());
        return true;
    }
}